package com.ybwh.springboot1.controller;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ybwh.springboot1.common.Response;
import com.ybwh.springboot1.model.vo.AreaVo;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author saytime
 * @since 2018-12-06
 */
@Controller
@RequestMapping("/area")
public class AreaController {

	@ResponseBody
	@RequestMapping("/validate")
	public Response<Object> validate(@Validated @ModelAttribute AreaVo areaVo, BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			for(ObjectError error : bindingResult.getAllErrors()) {
				return Response.failedResp(error.getDefaultMessage());
			}
		} 

		return Response.successResp(null);
	}

}
